package A1_二叉树;

public class LC_98验证二叉搜索树 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val=val;
        }
        TreeNode(int val,TreeNode left,TreeNode right){
            this.val=val;
            this.left=left;
            this.right=right;
        }
    }
    TreeNode pre=null;
    public boolean isValidBST(TreeNode root) {
        if(root==null)
            return true;
        boolean left=isValidBST(root.left);
        if(pre!=null && pre.val>=root.val)//[2,2,2]
            return false;
        pre=root;
        boolean right=isValidBST(root.right);
        return left && right;
    }
}
